# coding=utf-8
from __future__ import print_function
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _


class CreateUserForm(forms.Form):
    username = forms.CharField(required=True)
    password = forms.CharField(required=True)
    repass = forms.CharField(required=True)

    def clean(self):
        cleaned_data = super(CreateUserForm, self).clean()

        password = cleaned_data.get('password')
        repass = cleaned_data.get('repass')
        if not password or not repass or password != repass:
            self.add_error('password', ValidationError(_('密码不一致'), code='password'))

        return cleaned_data
